<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="UTF-8" />
    <meta name="keywords" content="" />
    <meta name="description" content="" />
    <title></title>
    <style></style>
  </head>
  <body>
    <div id="app">
      <form @submit.prevent="submit">
        <label>账号: </label>
        <input type="text" v-model="userForm.username" /><br /><br />
        <label>密码: </label>
        <input type="password" v-model="userForm.password" /><br /><br />
        <label>性别: </label>
        &nbsp;男<input
          type="radio"
          name="sex"
          :value="1"
          v-model="userForm.sex"
        />
        女<input
          type="radio"
          name="sex"
          :value="0"
          v-model="userForm.sex"
        /><br /><br />
        <label>爱好:</label> &nbsp; 抽烟
        <input type="checkbox" value="抽烟" v-model="userForm.hobbies" />
        喝酒
        <input type="checkbox" value="喝酒" v-model="userForm.hobbies" />
        烫头
        <input type="checkbox" value="烫头" v-model="userForm.hobbies" />
        <br /><br />
        <label>所属校区: </label>
        <select v-model="userForm.address">
          <option value="">请选择校区</option>
          <option value="wuhan">武汉</option>
          <option value="zhengzhou">郑州</option>
          <option value="tianjin">天津</option>
          <option value="shanghai">上海</option>
          <option value="ningxia">宁夏</option>
          <option value="yangtze">长江</option>
          <option value="liaoning">辽宁</option>
        </select>
        <br /><br />
        <label>其他信息:</label>
        <textarea rows="10" v-model="userForm.others"></textarea>
        <br /><br />
        <input type="checkbox" v-model="userForm.protocol" /> 阅读并接受
        《用户协议》 <br /><br />
        <!-- <button type="submit" @click.prevent="submit">提交</button> -->
        <button type="submit">提交</button>
      </form>
    </div>
    <script src="./js/vue.js"></script>
    <script>
      const vm = new Vue({
        data: {
          //用户表单数据
          userForm: {
            username: "",
            password: "",
            sex: 1,
            hobbies: [],
            address: "",
            others: "",
            protocol: true,
          },
        },
        methods: {
          //提交按钮的回调函数
          submit() {
            setTimeout(() => {
              console.log(this.userForm);
            }, 0);
          },
        },
        computed: {},
      });

      //在容器里面渲染元素
      vm.$mount("#app");
    </script>
  </body>
</html>
